<%--
  @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
    $(document).ready(function () {
        var pls_enter_department_name = "<br>" + document.getElementById("pls_enter_department_name").value;
        var pls_enter_department_address = "<br>" + document.getElementById("pls_enter_department_address").value;
        var pls_enter_submit_date = "<br>" + document.getElementById("pls_enter_submit_date").value;
        var pls_enter_contact_person = "<br>" + document.getElementById("pls_enter_contact_person").value;
        var pls_enter_valid_email = "<br>" + document.getElementById("pls_enter_valid_email").value;
        var pls_enter_valid_phone_No = "<br>" + document.getElementById("pls_enter_valid_phone_No").value;
        var pls_enter_valid_NIC_No = "<br>" + document.getElementById("pls_enter_valid_NIC_No").value;
        var pls_enter_valid_value = "<br>" + document.getElementById("pls_enter_valid_value").value;
        var pls_select_gn_division = $("#pls_select_gnDivision").val();
        $("#gov-land-init-ReleseToDepartment-application-form").validate({
            rules: {
                departmentNameId: {
                    required: true
                },
                submitDate: {
                    required: true,
                    isDateFormated: true
                },
                departmentAddressId: {
                    required: true
                },
                contactPersonId: {
                    required: true
                },
                departmentMobileId: {
                    phoneNo: true
                },
                departmentLandPhoneId: {
                    phoneNo: true
                },
                departmentEmailId: {
                    email: true
                },
                personMobileId: {
                    phoneNo: true
                },
                personLandPhoneId: {
                    phoneNo: true
                },
                personEmailId: {
                    email: true
                },
                gnDivisionId: {
                    selectBox: "default"
                }
            },
            messages: {
                departmentNameId: {
                    required: pls_enter_department_name
                },
                submitDate: {
                    required: pls_enter_submit_date
                },
                departmentAddressId: {
                    required: pls_enter_department_address
                },
                contactPersonId: {
                    required: pls_enter_contact_person
                },
                gnDivisionId: {
                    selectBox: pls_select_gn_division
                },
                departmentMobileId: pls_enter_valid_phone_No,
                departmentLandPhoneId: pls_enter_valid_phone_No,
                departmentEmailId: pls_enter_valid_email,
                personMobileId: pls_enter_valid_phone_No,
                personLandPhoneId: pls_enter_valid_phone_No,
                personEmailId: pls_enter_valid_email


            },
            invalidHandler: function (form, validator) {
                var errors = validator.numberOfInvalids();
                if (errors) {
                    var invalidPanels = $(validator.invalidElements()).closest(".ui-tabs-panel", form);
                    if (invalidPanels.size() > 0) {
                        $.each($.unique(invalidPanels.get()), function () {
                            $(this).siblings(".ui-tabs-nav")
                                    .find("a[href='#" + this.id + "']").parent().not(".ui-tabs-selected")
                                    .addClass("ui-state-error")
                                    .show("pulsate", {times: 3});
                        });
                    }
                }
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).removeClass(errorClass);
                $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
                var $panel = $(element).closest(".ui-tabs-panel", element.form);
                if ($panel.size() > 0) {
                    if ($panel.find("." + errorClass + ":visible").size() == 0) {
                        $panel.siblings(".ui-tabs-nav").find("a[href='#" + $panel[0].id + "']")
                                .parent().removeClass("ui-state-error");
                    }
                }
            }
        });
    });

    $(function () {
        var mode = document.getElementById("edit_mode").value;

        if (mode == 2) {
            var fieldIds = new Array('submitDate', 'departmentNameId', 'departmentAddressId', 'departmentMobileId',
                    'departmentLandPhoneId', 'departmentEmailId', 'departmentFaxlId', 'contactPersonId', 'designationId',
                    'personMobileId', 'personLandPhoneId', 'personEmailId', 'personFaxId', 'purposeId'
                    , 'alienationMethodId5', 'alienationMethodId6'
                    /*, 'planNoId', 'lotNoId'
                     , 'hectareId', 'acreId', 'roodsId', 'perchesId', 'purposeId'*/
                    , 'gnDivisionId',
                    'districtId',
                    'dsDivisionId'
            );
            enableFields(fieldIds);

        }
    });

    function getDsDivisionByDistrict() {
        var oSelect = document.getElementById('districtId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 2},
                        function (data) {
                            var ds = data.dsDivisionList;
                            for (var i = 0; i < ds.length; i++) {
                                options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                            }
                            $("select#dsDivisionId").html(options1);
                            //$("select#gnDivisionId").html('<option value="0"> -- Select -- </option> ');
                            $("select#gnDivisionId").html('<option value="0">' + $('#select').val() + '</option> ');
                        });
            }
        }
    }

    function getGnDivisionByDsDivision() {
        var oSelect = document.getElementById('dsDivisionId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 3},
                        function (data) {
                            var ds = data.gnDivisionList;
                            for (var i = 0; i < ds.length; i++) {
                                options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                            }
                            $("select#gnDivisionId").html(options1);
                        });
            }
        }
    }


</script>
<s:if test="editMode!=0">
    <div id="land-registration-module-home-title" class="module-home-title">
        <s:include value="../alienationApplicationNavigationInit.jsp"/>
    </div>
</s:if>
<div id="init-release-to-departments-application-outer" class="form-outer">
    <%-- <h2><s:label value="%{getText('initial_land_application.label')}"/> - <s:label
 value="%{getText('release_to_departments.label')}"/></h2>   --%>
    <h2><s:label value="%{getText('initial_land_application.label')}"/> - <s:label
            value="%{getText('alienation_for_departments.label')}"/></h2>
    <hr/>
    <s:form action="addInitLandApplication.do" method="POST"
            id="gov-land-init-ReleseToDepartment-application-form"
            onsubmit="javascript:return (validateFormForInputDataSyntaxErrors('gov-land-init-ReleseToDepartment-application-form') && selectList())"
            enctype="multipart/form-data">
        <fieldset class="submit-date-fieldset-style">
            <table class="submited-date-table">
                <tr>
                    <td><s:label value="%{getText('submit_date.label')}" cssClass="mandatory-field"/><s:label
                            value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                    <td><s:textfield id="submitDate" name="landApplication.submitDate"
                                     onKeyPress="return dateNumbersOnly(event,true)"/></td>
                </tr>
                    <%-- <tr>
                        <td>
                            <s:label value="%{getText('alienation_methods.label')}" cssClass="mandatory-field"/></td>
                        <td><s:checkboxlist list="alienationMethodSet" name="alienationMethodSelectedList"
                                            value="amSelectedList" theme="checkbox-theme"/></td>
                    </tr>--%>
                <tr>
                    <td><s:label value="%{getText('alienation_methods.label')}" cssClass="mandatory-field"/></td>
                    <td>
                        <s:radio id="alienationMethodId" list="alienationMethodSet" name="alienationType"/>
                    </td>
                </tr>
                <tr>
                    <td><s:label value="%{getText('purpose_of_the_requesting_land')}"/></td>
                    <td><s:textarea cssClass="width-610-px" name="landApplication.purpose" id="purposeId"/></td>
                </tr>
            </table>

        </fieldset>

        <div id="tabs">
            <ul>
                <li><s:a href="#departmentDetails"><s:label
                        value="%{getText('details_of_department.label')}"/></s:a></li>
                    <%-- <li><s:a href="#contactPersonDetail"><s:label
                value="%{getText('details_of_contact_person.label')}"/></s:a></li>    --%>
                <li><s:a href="#landAlienationDetails"><s:label value="%{getText('details_of_land.label')}"/></s:a></li>
            </ul>

            <div class="fieldset-style" id="departmentDetails">

                <table class="width-100" id="division">
                    <s:if test="viewMode">
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:textfield id="districtId" name="districtName" cssClass="width-200-px"
                                             disabled="true"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:textfield id="dsDivisionId" name="dsDivisionName" cssClass="width-200-px"
                                             disabled="true"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                <s:textfield id="gnDivisionId" name="holder.gnDivision.name" cssClass="width-200-px"/>
                            </td>
                        </tr>
                    </s:if>
                    <s:else>
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:select id="districtId" name="districtId" list="districtListAll"
                                          onchange="getDsDivisionByDistrict()" headerKey="0"
                                          headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:select id="dsDivisionId" name="dsDivisionId" list="dsDivisionList"
                                          onchange="getGnDivisionByDsDivision()" headerKey="0"
                                          headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                <s:select id="gnDivisionId" name="holder.gnDivision.id" list="gnDivisionList"
                                          headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/>
                            </td>
                        </tr>
                    </s:else>
                </table>

                <table class="width-100">
                    <tr>
                        <td colspan="4">
                            <s:include value="../instituteDetails.jsp"/>
                        </td>
                    </tr>
                </table>
                    <%--  <table class="width-100">
                    <tr>
                        <td><s:label value="%{getText('name_of_the_Department.label')}" cssClass="mandatory-field"/>
                        </td>
                        <td colspan="3"><s:textarea name="contactPerson.name" cssClass="width-500-px"
                                                    id="departmentNameId"/></td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('address_of_the_department.label')}" cssClass="mandatory-field"/>
                        </td>
                        <td colspan="3"><s:textarea cssClass="width-500-px" name="contactPerson.address"
                                                    id="departmentAddressId"/></td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('telephone.label')}"/></td>
                        <td><s:label value="%{getText('mobile.label')}"/></td>
                        <td colspan="2"><s:textfield name="contactPerson.mobile" id="departmentMobileId"/></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><s:label value="%{getText('land_phone.label')}"/></td>
                        <td colspan="2"><s:textfield name="contactPerson.landPhone" id="departmentLandPhoneId"/>
                        </td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('email.label')}"/></td>
                        <td><s:textfield name="contactPerson.email" id="departmentEmailId"/></td>
                        <td><s:label value="%{getText('fax.label')}"/></td>
                        <td><s:textfield name="contactPerson.fax" id="departmentFaxlId"/></td>
                    </tr>
                </table>
            </div>
            <div class="fieldset-style" id="contactPersonDetail">
                <table>
                    <tr>
                        <td><s:label value="%{getText('name.label')}" cssClass="mandatory-field"/></td>
                        <td colspan="3">
                            <s:textarea name="holder.name" cssClass="width-500-px" id="contactPersonId"/>
                        </td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('designation.label')}"/></td>
                        <td colspan="3"><s:textarea name="holder.designation" cssClass="width-500-px"
                                                    id="designationId"/></td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('telephone.label')}"/></td>
                        <td><s:label value="%{getText('mobile.label')}"/></td>
                        <td colspan="2"><s:textfield name="contacts.mobile" id="personMobileId"/></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><s:label value="%{getText('land_phone.label')}"/></td>
                        <td colspan="2"><s:textfield name="contacts.landPhone" id="personLandPhoneId"/></td>
                    </tr>
                    <tr>
                        <td><s:label value="%{getText('email.label')}"/></td>
                        <td><s:textfield name="contacts.email" id="personEmailId"/></td>
                        <td><s:label value="%{getText('fax.label')}"/></td>
                        <td><s:textfield name="contacts.fax" id="personFaxId"/></td>
                    </tr>
                </table>    --%>
            </div>


            <div class="fieldset-style" id="landAlienationDetails">
                <table class="width-100">
                    <s:include value="../landAlienationDetails.jsp"/>
                </table>
            </div>

        </div>


        <hr/>
        <s:hidden id="edit_mode" name="editMode"/>
        <s:include value="initFormSubmitButton.jsp"/>
        <%-- <div class="form-button-div right-align">
     <s:if test="editMode==0">
         <s:hidden name="editMode" value="0"/>
         <s:submit value="%{getText('save.label')}"/>
         <s:submit cssClass="cancel" action="landAlienationModuleHome" value="%{getText('back.label')}"/>
     </s:if>
     <s:if test="editMode==1">
         <s:submit cssClass="cancel" action="landAlienationModuleHome" value="%{getText('back.label')}"/>
         <s:hidden name="editMode" value="1"/>
         <s:submit value="Edit"/>
         <s:hidden name="landApplication.id"/>
         <s:hidden name="contacts.id"/>
         <s:hidden name="contactPerson.id"/>
         <s:hidden name="holder.id"/>
     </s:if>
 </div>
<s:hidden name="alienationType"/>
 <s:hidden name="initApplicationId" value="0"/>     --%>
    </s:form>
    <%--<s:include value="../approveRejectButton.jsp"/>--%>
</div>
<s:hidden id="pls_enter_department_name" value="%{getText('pls_enter_department_name')}"/>
<s:hidden id="pls_enter_submit_date" value="%{getText('pls_enter_submit_date')}"/>
<s:hidden id="pls_enter_department_address" value="%{getText('pls_enter_department_address')}"/>
<s:hidden id="pls_enter_contact_person" value="%{getText('pls_enter_contact_person')}"/>
<s:hidden id="pls_enter_valid_email" value="%{getText('pls_enter_valid_email')}"/>
<s:hidden id="pls_enter_valid_phone_No" value="%{getText('pls_enter_valid_phone_No')}"/>
<s:hidden id="pls_enter_valid_NIC_No" value="%{getText('pls_enter_valid_NIC_No')}"/>

<s:hidden id="pls_enter_valid_value" value="%{getText('pls_enter_valid_value')}"/>
<s:hidden id="pls_select_gnDivision" value="%{getText('pls_select_gnDivision.label')}"/>
<s:hidden id="select" value="%{getText('select.label')}"/>